﻿namespace random_enter
{
    internal class Program
    {
        enum command
        {
            Up,
            Down,
            Left,
            Right
        }
        static void Main(string[] args)
        {
            ConsoleKey input;
            //定义错误
            int wrong = 0;
            Console.Write("请输入你想要测试的次数： ");
            //定义测试总次数
            int num = int.Parse(Console.ReadLine());
            DateTime start = DateTime.Now;
            Console.WriteLine("测试开始！");
            for (int i = 1; i <= num; i++)
            {
                //生成枚举中的随机变量
                Random random = new Random();
                command button = (command)random.Next(0, 4);
                //清屏显示测试
                Console.Clear();
                Console.Write($"现在正在进行第{i}次试验   "); 
                Console.WriteLine($"总失误次数为： {wrong}");
                //输出随机按钮
                Console.WriteLine(button.ToString());
              
                input = Console.ReadKey(true).Key;

                switch (button)
                {
                    case command.Up:
                        if (input == ConsoleKey.UpArrow ) break;
                        else
                        {
                            wrong++;
                            break;
                        }
                    case command.Down:
                        if (input == ConsoleKey.DownArrow ) break;
                        else
                        {
                            wrong++;
                            break;
                        }
                    case command.Left:
                        if (input == ConsoleKey.LeftArrow  ) break;
                        else
                        {
                            wrong++;
                            break;
                        }
                    case command.Right:
                        if (input == ConsoleKey.RightArrow  ) break;
                        else
                        {
                            wrong++;
                            break;
                        }
                    default:
                        break;

                }

            }
            //记录游戏结束时间
            DateTime end = DateTime.Now;
            //记录总用时
            TimeSpan b = end - start;
            //清屏显示最终结果
            Console.Clear();
            Console.WriteLine($"总测试次数为:{num}");
            Console.WriteLine($"总用时为：{b.TotalSeconds}秒");
            Console.WriteLine($"总失误次数为： {wrong}");

        }
    }


}
